package com.orhon.smartcampus.modules.base.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

import com.orhon.smartcampus.modules.student.entity.Eclass;
import com.orhon.smartcampus.modules.teacher.entity.TInformation;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "base_grades", schema = "smartcloud", catalog = "")
public class Grades {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;
    @Column(name = "grade_slug", nullable = true, length = 191)
    private String gradeSlug;
    @Column(name = "grade_number", nullable = true, length = 191)
    private String gradeNumber;
    @Column(name = "grade_order", nullable = false)
    private Integer gradeOrder;
    @Column(name = "created_at", nullable = true)
    private Date createdAt;
    @Column(name = "updated_at", nullable = true)
    private Date updatedAt;
    @Column(name = "deleted_at", nullable = true)
    private Date deletedAt;
    @Column(name = "mark", nullable = true, length = 255)
    private String mark;
    @Column(name = "grade_name", nullable = true)
    private String gradeName;
    
  //"学段表"  
  	@OneToOne( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
  	@JoinColumn(name = "period_id")
  	@NotFound(action=NotFoundAction.IGNORE)
  	private Periods periods;

    //学校模块

  	@ManyToMany(cascade = CascadeType.ALL,  fetch = FetchType.LAZY)
    @JoinTable(
            name = "base_subjects_grade_relation",
            joinColumns = { @JoinColumn(name = "grade_id")},
            inverseJoinColumns = { @JoinColumn(name = "subject_id")}
    )
    @NotFound(action= NotFoundAction.IGNORE)
    @Where(clause = "ISNULL(deleted_at)")
    List<Subjects> subjects;

    //学校
    @ManyToMany(cascade = CascadeType.ALL,  fetch = FetchType.LAZY)
    @JoinTable(
            name = "base_teacher_grades_relation",
            joinColumns = { @JoinColumn(name = "grades_id")},
            inverseJoinColumns = { @JoinColumn(name = "teacher_id")}
    )
    @NotFound(action= NotFoundAction.IGNORE)
    @Where(clause = "ISNULL(deleted_at)")
    List<TInformation> teacher;


    //班级 
//    @OneToMany(cascade = CascadeType.ALL , fetch = FetchType.LAZY)
//    @Where(clause = "ISNULL(deleted_at)")
//    @JoinColumn(name = "grade_id")
//    @NotFound(action=NotFoundAction.IGNORE)
    @OneToMany(targetEntity = Eclass.class , mappedBy = "baseGradesByGradeId",  fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
    @NotFound(action= NotFoundAction.IGNORE)
    private List<Eclass> eclasses;


}
